package com.kischang.blog.model;

import javax.persistence.*;
import java.util.Random;

/**
 * Created by KisChang on 2015/5/31.
 */
@Entity
public class BrowseHistory {

    private long id;
    //访问者Id
    private User user;
    //访问的帖子
    private Topic topic;

    private String val;

    private static final String[] vals = {"3.0","3.5","4.0","4.5","5.0"};

    public BrowseHistory() {
    }

    public BrowseHistory(User user, Topic topic) {
        this.user = user;
        this.topic = topic;
        Random random = new Random(System.currentTimeMillis());
        val = vals[random.nextInt(5)];
    }

    @Id
    @GeneratedValue
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "uid")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "tid")
    public Topic getTopic() {
        return topic;
    }

    public void setTopic(Topic topic) {
        this.topic = topic;
    }

    public String getVal() {
        return val;
    }

    public void setVal(String val) {
        this.val = val;
    }
}
